import random

from hub import web
from util import html,plot

class DebugHandler(web.WebQuery):
    
    title = 'debug@home'

    def __init__(self,serviceName,logger,settings):
        self.logger = logger
        self.settings = settings
        web.WebQuery.__init__(self,serviceName)

    def GET(self,request,session,state,content):

        content.append(html.H1('Plotting Test'))
        # generate some random walk data
        randomWalk = [(0,0)]
        for step in xrange(100):
            x = 0.1*(step+1)
            y = randomWalk[-1][1] + random.gauss(0,0.1)
            randomWalk.append((x,y))
        # generate a raw plot series of this data
        raw = plot.PlotSeriesRaw(randomWalk)
        reduced = plot.PlotSeriesReduced(randomWalk,maxPoints=20,color='"blue"')
        smooth = plot.PlotSeriesReduced(randomWalk,maxPoints=20,smoothing=1.5,
            points='{show:true}',lines='{show:true}',color='"white"')
        frame = plot.PlotFrame(raw,reduced,smooth,id='plottest')
        content.append(frame.html())
        # dump the json text
        content.append(html.Pre(frame.jsonString()))  
        
    def POST(self,request,session,state):
        pass
